1
|
|
|
$(document).ready(function() { |
2
|
|
|
$(document).on('click', 'a[data-gototab]', function() { |
3
|
|
|
var tabName = $(this).attr('data-gototab'); |
4
|
|
|
$('li[data-tab-name="' + tabName + '"] a').trigger('click'); |
5
|
|
|
}); |
6
|
|
|
|
7
|
|
|
var countCollectionsInTabs = function() { |
8
|
|
|
var countableTabs = $('.countable-tab'); |
9
|
|
|
|
10
|
|
|
countableTabs.each(function(index) { |
|
|
|
|
11
|
|
|
var tab = $(this); |
12
|
|
|
tab.data('currentCount', 0); |
13
|
|
|
|
14
|
|
|
var countableClasses = $.grep(tab.attr("class").split(' '), function(v) { |
15
|
|
|
return v.match(/count-.*/); |
16
|
|
|
}); |
17
|
|
|
|
18
|
|
|
$.each(countableClasses, function(i, cls) { |
19
|
|
|
var collectionAsForm, collectionAsTable = 0; |
20
|
|
|
var fieldName = cls.replace('count-', ''); |
21
|
|
|
|
22
|
|
|
if (Admin.currentAdmin) { |
|
|
|
|
23
|
|
|
var fieldId = 'field_widget_' + Admin.currentAdmin.uniqid + '_' + fieldName; |
24
|
|
|
|
25
|
|
|
collectionAsForm = $('#' + fieldId + ' > div.sonata-ba-tabs > div'); |
26
|
|
|
collectionAsTable = $('#' + fieldId + ' > table > tbody > tr'); |
27
|
|
|
} else { |
28
|
|
|
var field = $('*[data-field-name="' + fieldName + '"]'); |
29
|
|
|
|
30
|
|
|
collectionAsForm = field.find('> div.box'); |
31
|
|
|
collectionAsTable = ''; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
tab.data('currentCount', parseInt(tab.data('currentCount'), 10) + ( |
35
|
|
|
parseInt(collectionAsForm.length, 10) + |
36
|
|
|
parseInt(collectionAsTable.length, 10) |
37
|
|
|
)); |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
var counterItem = tab.find('a > span.counter'); |
41
|
|
|
|
42
|
|
|
if (counterItem.length == 0) { |
43
|
|
|
counterItem = tab.find('a').append( |
44
|
|
|
$('<span/>').attr({ |
45
|
|
|
'class': 'counter' |
46
|
|
|
}) |
47
|
|
|
).find('.counter'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
counterItem.html(tab.data('currentCount')).attr('data-count', tab.data('currentCount')); |
51
|
|
|
}); |
52
|
|
|
}; |
53
|
|
|
|
54
|
|
|
countCollectionsInTabs(); |
55
|
|
|
|
56
|
|
|
$(document).on('sonata.add_element', function() { |
57
|
|
|
countCollectionsInTabs(); |
58
|
|
|
}); |
59
|
|
|
|
60
|
|
|
var cookieLastTab = getCookie('selectedTab'); |
61
|
|
|
|
62
|
|
|
if (cookieLastTab) { |
63
|
|
|
$('.nav-tabs li[data-tab-name="'+cookieLastTab+'"] a').trigger('click'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$(document).on('click', '.nav-tabs li[data-tab-name] a', function() { |
67
|
|
|
document.cookie = 'selectedTab=' + $(this).closest('li').data('tabName'); |
68
|
|
|
}); |
69
|
|
|
}); |
70
|
|
|
|
71
|
|
|
function getCookie(cname) { |
72
|
|
|
var name = cname + "="; |
73
|
|
|
var decodedCookie = decodeURIComponent(document.cookie); |
74
|
|
|
var ca = decodedCookie.split(';'); |
75
|
|
|
for (var i = 0; i < ca.length; i++) { |
76
|
|
|
var c = ca[i]; |
77
|
|
|
while (c.charAt(0) == ' ') { |
78
|
|
|
c = c.substring(1); |
79
|
|
|
} |
80
|
|
|
if (c.indexOf(name) == 0) { |
81
|
|
|
return c.substring(name.length, c.length); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
|
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.